import { api } from '@/utils/request'
import type { Photo, CreatePhotoRequest, UpdatePhotoRequest } from '@/types/photo'

// 获取所有照片
export const getPhotos = () => {
  return api.get<Photo[]>('/photos')
}

// 创建照片
export const createPhoto = (data: CreatePhotoRequest) => {
  return api.post<Photo>('/photos', data)
}

// 更新照片
export const updatePhoto = (id: number, data: UpdatePhotoRequest) => {
  return api.put<Photo>(`/photos/${id}`, data)
}

// 删除照片
export const deletePhoto = (id: number) => {
  return api.delete(`/photos/${id}`)
}

// 获取已删除的照片（回收站）
export const getDeletedPhotos = () => {
  return api.get<Photo[]>('/photos/deleted')
}

// 恢复照片
export const restorePhoto = (id: number) => {
  return api.put(`/photos/${id}/restore`)
}

// 永久删除照片
export const permanentDeletePhoto = (id: number) => {
  return api.delete(`/photos/${id}/permanent`)
}

// 上传照片文件
export const uploadPhoto = (file: File, description: string = '', uploadUserId: number) => {
  const formData = new FormData()
  formData.append('file', file)
  formData.append('description', description)
  formData.append('upload_user_id', uploadUserId.toString())

  return api.post<Photo>('/photos/upload', formData, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  })
}
